<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 递归 函数自调用
        function run(num){
            // console.log("run",num);
            if(num == 0) return 0;
            return run(num - 1) + num;
        }        
        console.log(run(5));

        // function a(){
        //     console.log("===");
        //     b()
        //     console.log("aaaa");
        // }
        // function b(){
        //     console.log("bbbb");
        // }
        // a()

        // 利用递归实现多级遍历，以及深克隆。
        var data1 = [{
            title:"biaot",
            arr:["a","b","c"],
            obj:{
                name:"aaa",
                arr1:["aaa","bbb","ccc"]
            }
        },{
            title:"标题2",
            arr:["2a","3b","4c"],
            obj:{
                name:"222aaa",
                arr1:["2aaa","2bbb","2ccc"]
            }
        },{
            title:"标题23",
            arr:["3a","3b","3c"],
            obj:{
                name:"333aaa",
                arr1:["3aaa","3bbb","3ccc"]
            }
        }]

        var obj = {
                name:"333aaa",
                arr1:["3aaa","3bbb","3ccc"]
            }

        // 递归的深拷贝
        function clone(data){
            if(typeof data != "object") return data;

            var yinyong = data instanceof Array ? [] : {};
            for(var key in data){
                // data[key] //如果是基本数据类型,直接赋值 如果不是,需要再次循环
                yinyong[key] = clone(data[key]);
            }
            return yinyong;
        }
        var aaa = clone(obj);
        console.log(aaa);

        // aaa[2].obj.name = "lili";
        // console.log(aaa);

        // console.log(data1);

    </script>
</body>
</html>